package com.penghaisoft.microwms.product.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.penghaisoft.microwms.common.service.BaseService;
import com.penghaisoft.microwms.common.dto.Resp;
import com.penghaisoft.microwms.common.page.Pager;
import com.penghaisoft.microwms.product.dao.ProHandOutSnMapper;
import com.penghaisoft.microwms.common.data.model.ProHandOutSn;
import com.penghaisoft.microwms.product.service.IProHandOutSnService;

/**
 * <p>
 * 业务逻辑实现类
 * </p>
 * 
 * @author
 * @createDate 
 **/
@Service("proHandOutSnService")
public class ProHandOutSnServiceImpl extends BaseService implements IProHandOutSnService{
		@Resource
		private ProHandOutSnMapper proHandOutSnMapper;
		
	  /**
	   * 新增记录
	   * @param baseResource
	   * @return
	   */
		@Override
		public Resp create(ProHandOutSn proHandOutSn){
			proHandOutSnMapper.create(proHandOutSn);
			return success();
		}

	  /**
	   * 删除记录（逻辑删除）
	   * @param baseResource
	   * @return
	   */
		@Override
		public Resp delete(ProHandOutSn proHandOutSn){
			proHandOutSnMapper.delete(proHandOutSn);
			return success();
		}
		
	  /**
	   * 查询列表
	   * @param pager
	   * @param baseResource
	   * @return
	   */
		@Override
		public Pager<ProHandOutSn> findListByCondition(int page, int rows,ProHandOutSn condition){
		    Pager<ProHandOutSn> pager = new Pager<>();
		    pager.setPage(page);
		    pager.setRows(rows);
    		condition.preQuery();
    		long size = proHandOutSnMapper.queryCount(condition);
    		List<ProHandOutSn> records = new ArrayList<ProHandOutSn> ();
    		if(size > 0){
    			records = proHandOutSnMapper.queryList(pager,condition);
    		}
			pager.setRecords(records);
			pager.setTotalCount(size);
			return pager;
		}

	  /**
	   * 查询单条
	   * @param id
	   * @return
	   */
		@Override
		public ProHandOutSn findById(String id){
			return proHandOutSnMapper.queryById(id);
		}
		
	  /**
	   * 修改记录
	   * @param baseResource
	   * @return
	   */
		@Override
		public Resp update(ProHandOutSn proHandOutSn){
			proHandOutSnMapper.updateBySelect(proHandOutSn);
			return success();
		}

	@Override
	public List<ProHandOutSn> queryListByAny(ProHandOutSn condition) {
		condition.preQuery();
		return proHandOutSnMapper.queryByAny(condition);
	}

	@Override
	public Long queryCount(ProHandOutSn condition) {
		return proHandOutSnMapper.queryCount(condition);
	}

	@Override
	public Pager<ProHandOutSn> queryOrder(int page, int rows, ProHandOutSn proHandOutSn) {
		Pager<ProHandOutSn> pager = new Pager<>();
		pager.setPage(page);
		pager.setRows(rows);
//		condition.preQuery();
		List<ProHandOutSn> list = proHandOutSnMapper.queryPOutOrder(proHandOutSn);
		if(list.size() > 0){
			ProHandOutSn total = proHandOutSnMapper.queryTotal(proHandOutSn);
        	pager.setOrder("{\"codeNum\":\"" + total.getCodeNum()
        			+ "\",\"codeWt\":\"" + total.getCodeWt().stripTrailingZeros().toPlainString() + "\"}");
		}
		pager.setRecords(list);
		pager.setTotalCount(list.size());
		return pager;
	}

}
